using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Consul;
using ZhaoXi.MSACommerce.Authentication.JwtBearer;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Configuration.AddOcelot(
    folder: "./ocelot",
    env: builder.Environment,
    mergeTo: MergeOcelotJson.ToMemory,
    optional: false, reloadOnChange: true);
 
builder.Services.AddOcelot().AddConsul();
builder.Services.AddJwtBearer(builder.Configuration);
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI(options =>
    {
        options. SwaggerEndpoint(url:"/swagger/v1/swagger.json", name: "Gateway V1");
        options. SwaggerEndpoint( url: "/auth/swagger.json", name: "AuthServer V1");
        options. SwaggerEndpoint( url: "/user/swagger.json", name: "UserService V1");
        options. SwaggerEndpoint( url: "/verification/swagger.json", name: "MsmService V1");
    });
}
app.UseOcelot().Wait();


app.Run();
